﻿@{
    ViewBag.Title = "商品出库单";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}

<table id="dg" class="easyui-datagrid" style="width:100%; height: 750px;"
       url="/GoodsOrder/GetLKWarehouseOutPageList" toolbar="#tb" title="商品出库单" rownumbers="true" pagination="true"
       pagelist="[15]" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="BillNo" align="right" width="80">
                出库单编号
            </th>
            <th field="OutTime" align="right" width="80" formatter="formatter_OutTime">
                出库时间
            </th>
            <th field="CustomerNo" align="right" width="80">
                客户编号
            </th>
            <th field="CustomerName" align="right" width="80">
                客户名称
            </th>
            <th field="TotalTon" align="right" width="80">
                总吨重
            </th>
            <th field="Total" align="right" width="80">
                总件数
            </th>
            <th field="Amount" align="right" width="80">
                总金额
            </th>
            <th field="IsReview" align="right" width="80" formatter="formatter_IsReview">
                是否复核
            </th>
            <th field="CreateTime" align="right" width="80" formatter="formatter_CreateTime">
                创建时间
            </th>

            <th field="ModifyUser" align="right" width="80">
                修改人
            </th>
            <th field="ModifyTime" align="right" width="80" formatter="formatter_ModifyTime">
                修改时间
            </th>
            <th field="Remark" align="right" width="80">
                备注
            </th>
            <th field="BillSource" align="right" width="180">
                单据来源
            </th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <span>出库单号</span>
    <input id="BillNo" class="easyui-textbox " style="width: 173px; height: 30px;" />
    <span>客户名称</span>
    <input type="hidden" id="hdselectKeyword" />
    <input name="SelectCustomer" id="SelectCustomer" class="easyui-combobox" style="width: 173px; height: 30px;" />
    <span>仓库</span>
    <input id="SelectWareHouseId" class="easyui-combobox" style="width: 173px; height: 30px;" />
    <span>开始时间</span>
    <input class="easyui-datebox" name="BeginTime" id="BeginTime" style="width: 173px; height: 30px; ">
    <span>结束时间</span>
    <input class="easyui-datebox" name="EndTime" id="EndTime" style="width: 173px; height: 30px; ">
    <div style="padding-top:5px;">
        <span>商品批号</span>
        <input id="GoodsCode" class="easyui-textbox " style="width: 173px; height: 30px;" />
        <span>商品名称</span>
        <input id="GoodsName" class="easyui-textbox " style="width: 173px; height: 30px;" />
        <span>规格</span>
        <input id="GoodsSpec" class="easyui-textbox " style="width: 173px; height: 30px;" />
    </div>
    @*<span>修改开始时间</span>
            <input class="easyui-datebox" id="ModifyBeginTime" style="width: 173px; height: 30px; ">
            <span>修改结束时间</span>
            <input class="easyui-datebox" id="ModifyEndTime" style="width: 173px; height: 30px; ">
            <span>修改人</span>
            <select class="easyui-combogrid" id="ModifyUserId" style="width:173px" data-options="
            panelWidth: 500,
            idField: 'EmployeeId',
            textField: 'EmpName',
            url: '/EmployeeInfo/GetEmployeeInfoListCombogrid',
            method: 'post',
            mode: 'remote',
            columns: [[
                {field:'EmpNum',title:'工号',width:80},
                {field:'EmpName',title:'姓名',width:80},
                {field:'EmpMobile',title:'手机号',width:80,align:'right'},
                {field:'DepName',title:'部门名称',width:80,align:'right'},
                {field:'LevelName',title:'岗位',width:80},
            ]],
            fitColumns: true,
            labelPosition: 'top'
        "></select>*@
<div>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addLKWarehouseOut()">新建</a>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editLKWarehouseOut()">编辑</a>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-ok" plain="true" onclick="checkLKWarehouseOut()">复核</a>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-print" plain="true" onclick="print()">打印</a>
    <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delLKWarehouseOut()">删除</a>
    <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
</div>

</div>

<script src="~/Content/js/jquery-easyui-1.4/datagrid-detailview.js"></script>
<script src="~/Js/Global.js"></script>
<script language="javascript" type="text/javascript">
    $(function () {
        InitSelectWareHouse();
        InitSelectCustomer();
        InitdgDetail();
    });

    $('#dg').datagrid({
        // 其他配置...
        onDblClickRow: function (rowIndex, rowData) {
            editLKWarehouseOut();
        }
    });

    function InitdgDetail() {
        $('#dg').datagrid({
            view: detailview,
            detailFormatter: function (index, row) {
                return '<div style="padding:2px;position:relative;"><table class="ddv"></table></div>';
            },
            onExpandRow: function (index, row) {
                var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                ddv.datagrid({
                    url: '/GoodsOrder/GetKWarehouseOutDetails?outId=' + row.Id,
                    fitColumns: true,
                    singleSelect: true,
                    rownumbers: true,
                    loadMsg: '',
                    height: 'auto',
                    columns: [[
                        { field: 'GoodsNo', title: '商品批次', width: 150 },
                        { field: 'GoodsName', title: '商品名称', width: 200 },
                        { field: 'GoodsSpecName', title: '规格', width: 200 },
                        { field: 'WareHouseName', title: '仓位', width: 100 },
                        { field: 'Weight', title: '件重', width: 100 },
                        { field: 'Number', title: '入库数量', width: 100 },
                        { field: 'TonWeight', title: '吨重', width: 100 },
                    ]],
                    onResize: function () {
                        $('#dg').datagrid('fixDetailRowHeight', index);
                    },
                    onLoadSuccess: function () {
                        setTimeout(function () {
                            $('#dg').datagrid('fixDetailRowHeight', index);
                        }, 0);
                    }
                });
                $('#dg').datagrid('fixDetailRowHeight', index);
            }
        });
    }

    function addLKWarehouseOut() {
        window.location.href = "/GoodsOrder/AddLKWarehouseOut";
    }


    function doSearch() {
        $('#dg').datagrid('load', {
            BillNo: $('#BillNo').val(),
            CustomerId: $('#SelectCustomer').combobox('getValue'),
            WareHouseId: $('#SelectWareHouseId').combobox('getValue'),
            /*IsValid: $('#IsValid').combobox('getValue'),*/
            BeginTime: $('#BeginTime').datebox('getValue'),
            EndTime: $('#EndTime').datebox('getValue'),
            GoodsCode: $('#GoodsCode').val(),
            GoodsName: $('#GoodsName').val(),
            GoodsSpec: $('#GoodsSpec').val(),
            //ModifyUserId: $('#ModifyUserId').combogrid('getValue'),
            //ModifyBeginTime: $('#ModifyBeginTime').datebox('getValue'),
            //ModifyEndTime: $('#ModifyEndTime').datebox('getValue')
        });
    }

    function querycustomer() {
        $("#SelectCustomer").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText").val() });
    }
    function querycustomer2() {
        $("#CustomerId").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText2").val() });
    }

    function editLKWarehouseOut() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要编辑的信息?');
            return;
        }
        window.location.href = "/GoodsOrder/EditLKWarehouseOut?id=" + row.Id;
    }

    function checkLKWarehouseOut() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要复核的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要复核吗?', function (r) {
            if (!r) { return false; }
            $.post("/GoodsOrder/ReviewLKWarehouseOut", { id: row.Id }, function (json) {
                Helper.Show(json.Msg);
                if (json.Success) {
                    doSearch();
                }
            });
        });
    }

    function delLKWarehouseOut() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/GoodsOrder/DeleteLKWarehouseOut", { id: row.Id }, function (json) {
                Helper.Show(json.Msg);
                if (json.Success) {
                    doSearch();
                }
            });
        });
    }

    function saveLKWarehouseOut() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').datagrid('reload');
                }
            }
        });
    }

    function formatter_IsValid(value, rowData, rowIndex) {
        return rowData.IsValid ? '启用' : '停用';
    }

    function formatter_IsByTon(value, rowData, rowIndex) {
        return rowData.IsByTon ? '是' : '否';
    }
    function formatter_IsReview(value, rowData, rowIndex) {
        return rowData.IsReview ? '是' : '否';
    }

    function formatter_ColdUnitPrice(value, rowData, rowIndex) {
        return rowData.ColdUnitPrice.toFixed(2);
    }

    function formatter_OutTime(value, rowData, rowIndex) {
        return formatdate(rowData.OutTime);
    }
    function formatter_CreateTime(value, rowData, rowIndex) {
        return formatdate(rowData.CreateTime);
    }
    function formatter_ModifyTime(value, rowData, rowIndex) {
        return formatdate(rowData.ModifyTime);
    }
    function formatter_ContractTime(value, rowData, rowIndex) {
        return formatdate(rowData.ContractTime);
    }

    function print() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要打印的数据');
            return false;
        }
        var printUrl = "/GoodsOrder/LKWarehouseOutPrint?id=" + row.Id;
        window.open(printUrl, "_blank");
    }
</script>





